Results 1 to 7 of 7

Thread: local.player.fireheld, explain please?

  1. #1

    Default local.player.fireheld, explain please?

    Okay can someone tell me if I have other options, besides fireheld? Basically I'm doing a trigger that works the same way as Rookie One's Survival Horror mod, you're invisible and upon firing you light up. Here's the section of script that lights them up.

    Code:
    While($player.hidden == 1)
    	{
    		if($player.fireheld)
    		{
    				$player light (randomfloat(0.999)) (randomfloat(0.999)) (randomfloat(0.999)) 750
    				$player show
    				$player.hidden = 0
    				wait 1
    				$player light (randomfloat(0.999)) (randomfloat(0.999)) (randomfloat(0.999)) 750
    				wait 0.5
    				$player light (randomfloat(0.999)) (randomfloat(0.999)) (randomfloat(0.999)) 750
    				wait 1.3
    				$player light (randomfloat(0.999)) (randomfloat(0.999)) (randomfloat(0.999)) 750
    				wait .3
    				$player lightOff
    				$player hide
    				$player.hidden = 1
    		}
    		if(($player.health < 1) || ($player.isDead == 1))
    			$player.hidden = 0
    			wait 1
    			thread give
    	}
    	
    end

    My problem is... People don't light up when they shoot, they only light up if they literally HOLD the fire button. and if this script looks tacky at the moment i apologize, I've returned after a very long hiatus and i'm trying to get the hang of it again. That and I've rewritten this script every possible way I can think of.

  2. #2
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Try something like
    local.player.hidden = 1;
    while(local.player && isAlive(local.player))
    {
        if (local.player.fireheld) {
            local.player light (randomfloat(1.0)) (randomfloat(1.0)) (randomfloat(1.0)) 750;
            local.player show;
            local.player.hidden = 0;
            local.player.hideTime = level.time + 0.25;
        }
    
        if (!local.player.hidden && level.time >= local.player.hideTime) {
            local.player lightOff;
            local.player hide;
            local.player.hidden = 1;
        }
        waitframe;
    }
    wait 1;
    thread give;


    Things to note:
    (1) Using $player as an entity instead of an array of entities only makes sense in single player. This snippet assumes your mod is designed for multiplayer and local.player points to the player entity in question.
    (2) Don't check the health property of a player entity, use the isAlive() command instead.
    (3) Fireheld will return true if the player is hold the fire button at that very moment. Your script will happily continue lighting the player even when he lets go of the button because you're using arbitrary waits
    in your looping logic.
    (4) Writing loops can be tricky.
    (4a) Essentially, what you're trying to do each iteration is first and foremost assert your invariables. These are the things that must be true, otherwise there would be no point in executing the body of the loop.
    For example, if the player has left the server, local.player will be NULL and the loop will end prematurely. Depending on what you're doing there, you may have to assert some invariables later inside the loop.
    (4b) In the body of the loop you assess which conditions are true or false at that point in time. Time being the keyword here. The purpose of loops such as this is to assess the situation at specific intervals and
    respond accordingly so you can't just use arbitrary waits. By the time the wait is over, the player might have died, stopped holding the fire button or left the server. The loop in the snippet will assess the player's
    situation every frame which is typically 20 fps or 0.05 seconds on the server (even if you host locally). You would not want to lower the wait interval even further, not unless it is absolutely necessary.
    (4c) By processing each interval, you may have to schedule and time certain events in the future (given the right conditions of course) so you'd need a way to tell the time. Luckily, level.time is a global variable
    which gives you the time that has passed and is updated every frame. We capture its value and add 5 frames' worth of milliseconds to it so 0.25 seconds is the minimum time the light has effect. Now in your
    script, you vary the colours of the light. You'd have use the same level.time technique in order to achieve that effect. This is also the way Rookie did it in his mod.

    I hope this refreshes your memory somewhat. I'm always glad to see people come back to modding for AA.
    Last edited by Sor; June 12th, 2015 at 04:27 AM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  3. #3

    Default

    Thank you very much, this functions perfectly I really appreciate the breakdown and tips, I will reference back to this post I'm sure. Also will have to change a few other threads and things in different maps lol.

    But I do have 3 questions. I'm not sure if I even knew this back in the day but....


    Code:
    if (local.player.fireheld) {
    I see you put the "{" on the same line as the "if" statement, is this personal preference or is there a benefit from this? I've always done it at the next line.
    Code:
    local.player light (randomfloat(1.0)) (randomfloat(1.0)) (randomfloat(1.0)) 750;
    Can you explain the use of the ";" in this line? I'm not sure if I've ever used it before, but it almost seems familiar.
    Code:
    if (!local.player.hidden && level.time >= local.player.hideTime) {
    Also explain the use of the "!" in this line, as other lines just say "if (local..." without the "!." Curious as to it's use.

    Sorry I'm so illiterate at this at the moment lol, it's been years since I've last done any scripting, and I've had plenty of parties in those years, so some things have been long forgotten lol.

  4. #4
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,259

    Default

    Hey

    1.
    { on the same line as the if statement is just personal preference, i do it on the next line, i find it makes code easier to read, but doesnt affect the code.

    2.
    A semicolon is more used in other languages as line/code breaks, to separate code used on the same line. Languages such as C# and SQL have to use this AFAIK. It isnt necessary but good habits i suppose.

    3.
    ! is used to represent IS NOT .
    so if(!local.player.hidden)
    means that if local.player.hidden IS NOT true(1) then....

    if(!local.player.hidden) is the same as if(local.player.hidden != 1)

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




  5. #5
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,071

    Default

    PurpleElephant nailed it on the head, and Sor, great break down! That's awesome support!!!

    I suck at moh scripting myself, but I always use the brackets after the function and or if/for/while loop statements. It really is a personal preference, but like PE mentioned above, I find it easier to follow when everything is mirrored\symmetrical in code.

    And yes, the semicolon is used in many languages. It basically is the end of that code segment. Not necessarily line break in the sense that it inputs like a "white space or new line" in your output, just a "best practice" I suppose you can say... I always have a tendency to do this, but it's probably because I'm always programming in c\c++ and it's required haha.

    And welcome to the forums man!

  6. #6
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Programming languages require the semicolon to signal the end of a single instruction (not to be confused with CPU instructions as that depends on what you're doing in that instruction and how it is compiled to machine code). Scripting languages are far less strict about it. In MoH and other scripting languages, the line break serves this purpose as well. Without a semicolon, though, you can't put multiple instructions on the same line. It has become a habit, I guess.

    EDIT: In fact, in many programming languages you can spread out an instruction over multiple lines if it's too long otherwise since all line breaks and whitespace is ignored by default. In MoH, you can only do this if you use a backslash (that is immediately followed by a line break) like this:
    waitthread Find local.needle \
                    local.haystack \
                    local.index \
                    local.count \
                    local.ignoreCase \
                    local.backwards;


    You can use curly brackets any way you want. It's just a matter of preference. Personally, I never use brackets if the body of my if/while/for statement contains a single instruction. Many languages will interpret the next instruction as the body of the statement if no brackets are found. Some compilers may complain if you didn't indent that instruction properly. If the body of a if/while/for is sufficiently small, I use a bracket on the same line as the statement itself. In all other cases, I put the bracket on the next line such as for methods, classes, namespaces, lengthy statements...
    The parentheses I used with the isAlive command are not required. In fact, your script won't compile if you try to do this for a command that expects more than one argument. Most other languages have function call syntax that use parentheses so again, this is a matter of preference.

    The NOT operator (or absence of it) means you are trying to assert whether a variable IS or IS NOT. Essentially, you're trying to determine whether the variable contains a value that will always evaluate true or false for that data type. Just remember that any value of any data type will evaluate true unless it is zero (for integers and floats), empty string (for strings), NULL (for entities), NIL (for pretty much any data type) or ( 0 0 0 ) (for vectors). I really miss this feature in languages like Java and .NET. I haven't had the opportunity to program in C, but as far as I know, the same principles apply there as well.
    Last edited by Sor; June 12th, 2015 at 04:34 AM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  7. #7

    Default

    Well I appreciate this crash course from everyone, lol. Gotta say you guys know how to welcome new members

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •